package com.freecloud.whispered.auth.repository;


import com.freecloud.framework.repository.BaseDao;
import com.freecloud.whispered.auth.entity.SysMenuEntity;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 菜单管理
 * 
 * @author maomao
 * @email 138383877@qq.com
 */
@Repository
public interface SysMenuDao extends BaseDao<SysMenuEntity,Long> {
	
	/**
	 * 根据父菜单，查询子菜单
	 * @param parentId 父菜单ID
	 */
	List<SysMenuEntity> findByParentId(Long parentId);
	
	/**
	 * 获取不包含按钮的菜单列表
	 */
	@Query("select u from SysMenuEntity u where u.type <> 2 order by u.orderNum asc ")
	List<SysMenuEntity> queryNotButtonList();
	
	/**
	 * 查询用户的权限列表
	 */
	@Query(value="select distinct m.*" +
			" from sys_user_role ur  " +
			" LEFT JOIN sys_role_menu rm on ur.role_id = rm.role_id  " +
			" LEFT JOIN sys_menu m on rm.menu_id = m.menu_id  " +
			" where ur.user_id = :userId order by m.order_num asc",nativeQuery=true)
	List<SysMenuEntity> queryUserList(@Param("userId") Long userId);
}
